-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add hook for provider version checking #51
Conversation
f8f213e
to
6f2bda0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of requiring x.x.x
could we just fail if it contains > or ~ ? Or something along those lines.
For example, I could definitely see us testing prerelease builds.
6f2bda0
to
75e5003
Compare
yeah I didn't think about the pre-releases. |
79c3dea
to
e447bd1
Compare
made the updates! |
e447bd1
to
425fe53
Compare
next; | ||
} else { | ||
# If the line contains a version, remove the prefix | ||
gsub(version_prefix_regex, "", $0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have used match with capture groups but it wasn't working on macos. I think it's a gawk specific function and depends on the os.
@@ -0,0 +1,54 @@ | |||
#! /bin/awk |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AWK is fine, but I wonder if it would be easier if we used python (since it's available already as pre-commit uses python)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought of it as well but I thought we wouldn't have access to it since we're removing the .python-version
files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can leave that in... and/or just assume that python is present.
@@ -13,3 +13,11 @@ | |||
language: script | |||
files: \.tf$ | |||
exclude: ^outputs\..*\.tf$ | |||
|
|||
- id: provider-pinned-versions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add to the readme this hook and how to use it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we don't have any docs about hooks
|
||
required_providers { | ||
aws = { | ||
version = "5.78.0" |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that there is still an unused variable that should be cleaned up.
We can revisit whether or not it would be easier for people to use simple grep or hcl2json or something along those lines later.
d529054
to
0c930e3
Compare
Release notes previewBelow is a preview of the release notes if your PR gets merged. 1.4.0 (2024-12-10)Features
Bug Fixes
Build System
Continuous Integration
Miscellaneous
Documentation |
simple grep wasn't so simple to implement (at least for me). I tried to stay away from any "non scripting" language but it was kind of a pain to implement TBH. At least I got to learn some AWK :) |
This pre-commit hook checks that the provider versions don't contain any constraints and thus are pinned. Version constraints include any of the following characters:
<>!~
.You can try the hook locally by cloning this rep, checking out this PR and running this in your terraform repo:
pre-commit try-repo ~/code/standards-terraform provider-pinned-versions --all-files
Example success:
terraform.tf
:Example failure:
terraform.tf
: